
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import EslintPlugin from 'vite-plugin-eslint'
import path from 'path'
import legacy from '@vitejs/plugin-legacy';

// https://vitejs.dev/config/
export default defineConfig({
    base: './',
    server: {
      port: 9530,
      proxy: {
        '/api': {
          target: 'https://service.yishifuwu.cn',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    build: {
      target: ['es2020', 'edge88', 'firefox78', 'chrome87'] // 兼容旧浏览器的目标
    },
    plugins: [
      legacy({
        targets: ['defaults', 'not IE 11']
      }),
      vue(),
      AutoImport({
        dirs: ['src/store'],
        imports: ['vue', 'vue-router', 'pinia', '@vueuse/core', {
          'ant-design-vue': ['Form']
        }], // 自动导入vue和vue-router相关函数
        dts: 'types/auto-import.d.ts', // 生成 `auto-import.d.ts` 全局声明
        eslintrc: {
          enabled: false, // 默认false, true启用。生成一次就可以，避免每次工程启动都生成
          filepath: './.eslintrc-auto-import.json', // 生成json文件
          globalsPropValue: true
        }
      }),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false, // css in js
          }),
        ]
      }),
      EslintPlugin({
        cache: false,
        exclude: ['./node_modules/**'], // 修正拼写
        include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx']
      })
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    css: {
      // css预处理
      preprocessorOptions: {
        less: {
          additionalData: '@import "@/styles/globalVariable.less";',
          javascriptEnabled: true
        }
      },
      postcss: {
        plugins: [
        ]
      }
    }
  })
